package lab_1;

import java.io.IOException;
import java.io.InputStreamReader;
import java.rmi.RemoteException;
import java.rmi.Naming;
import java.net.MalformedURLException;

/**
 *
 * @author grp02 - Pascal Charreix and Meike Paetz
 *
 * Lab1 is the Holiday Packages Server. This class registers SmartTours and
 * TravelAgency with the registry to get remote access.
 */
public class Lab_1 {

    /**
     *  Main class creating, starting and binding the server
     */
    public static void main(String[] args) {
        int i = 0;
        String host = "//:1099/";
        ManagerImpl Manager;
        try {
            Manager = new ManagerImpl();
            try
            {
                System.out.println("Starting server : " + host);
                Naming.rebind(host + "grp02Manager", Manager);
                System.out.println("Registered Manager as grp02Manager.");
            } catch (RemoteException a) {
                System.err.println("if registry could not be contacted\n" + a.getMessage());
            } catch (MalformedURLException a) {
                System.err.println("if the name is not an appropriately formatted URL\n" + a.getMessage());
            }
            System.out.println("To end program, type Q or q, " + "then <return>.");
            char answer = '\0';
            InputStreamReader inputStreamReader = new InputStreamReader(System.in);
            while (!((answer == 'q') || (answer == 'Q'))) {
                try {
                    answer = (char) inputStreamReader.read();
                } catch (IOException e) {
                    System.err.println("I/O exception: " + e.toString());
                }
            }
            System.out.println("Manager server is stopped.");
            System.exit(0);
        } catch (RemoteException re) {
            System.err.println("Remote exception while creating/registering: " + re.getMessage());
        }
    }
}
